package cn.wolfcode.tx;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

// 模拟处理事务类
@Component
@Aspect
public class MyTransactionManager {

	// 定义切入点
	@Pointcut("execution (* cn.wolfcode.service.impl.*ServiceImpl.*(..))")
	public void txPoint() {

	}

	@Before("txPoint()")
	public void begin() {
		System.out.println("开启事务");
	}

	@AfterReturning("txPoint()")
	public void commit() {
		System.out.println("提交事务");
	}

	@AfterThrowing(value="txPoint()",throwing="ex")
	public void rollback(Throwable ex) {
		System.out.println("回滚事务" + ex.getMessage());
	}

}
